package com.uphea;

import javax.servlet.http.HttpServletRequest;

import jodd.decora.DecoraManager;
import jodd.util.Wildcard;

/**
 * Application custom Decora manager.
 */
public class AppDecoraManager extends DecoraManager {

	/**
	 * Resolves decorators for action paths. In additional to defaults, we need
	 * to enable decoration for "/q/*" paths as well.
	 */
	@Override
	public String resolveDecorator(HttpServletRequest request, String actionPath) {
		if (actionPath.endsWith(".js")) {
			return null;
		}
		if (actionPath.endsWith("ExceptionLogServlet")) {
			return null;
		}
		if (Wildcard.match(actionPath, "/dwr/*")) {
			return null;
		}
		if (Wildcard.match(actionPath, "/js/*")) {
			return null;
		}
		if (Wildcard.match(actionPath, "/console/*")) {
			return null;
		}
		if (Wildcard.match(actionPath, "*/res/**")) {
			return null;
		}
		if (Wildcard.match(actionPath, "*/q/**")) {
			return null;
		}
		return null; // mmm 返回默认的装饰器页面

		// return null;
	}

	@Override
	public boolean decorateRequest(HttpServletRequest request) {
		StringBuffer requestURL = request.getRequestURL();
		String string = requestURL.toString();
		if (string.endsWith(".js")) {
			return false;
		}
		if (string.endsWith(".dwr")) {
			return false;
		}
		if (string.endsWith(".do")) {
			return false;
		}
		if (string.endsWith(".gif")) {
			return false;
		}
		if (string.endsWith(".css")) {
			return false;
		}
		if (string.endsWith("header.jsp")) {
			return false;
		}
		if (string.endsWith("query.jsp")) {
			return false;
		}
		if (string.endsWith("help.jsp")) {
			return false;
		}
		if (string.endsWith("frame.jsp")) {
			return false;
		}
		// if (string.endsWith("helpTranslate.jsp")) {
		// return false;
		// }
		if (string.endsWith("login.do")) {
			return false;
		}
		if (string.equals("/")) {
			return false;
		}
		if (string.endsWith("index1.html")) {
			return false;
		}
		if (string.endsWith("index.jsp")) {
			return false;
		}
		if (string.endsWith("ProcessData")) {
			return false;
		}
		if (string.endsWith("Log")) {
			return false;
		}
		return super.decorateRequest(request);
	}
}
